package com.cn.lottery.controller;

import java.util.Map;
import java.util.UUID;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cn.lottery.Server.Server;

@Controller
@RequestMapping("/lottery")
public class LotteryController {

	@Resource
	private Server server;
	
    @RequestMapping(value = "/start/{openid}",method=RequestMethod.GET,produces = "text/json;charset=UTF-8")
    @ResponseBody
    public Object lottery(@PathVariable(value = "openid") String openid){
		 return server.lotteryStart(openid);
	}
    
    @RequestMapping(value = "/search/{openid}",method=RequestMethod.GET,produces = "text/json;charset=UTF-8")
    @ResponseBody
    public Object searchLottery(@PathVariable(value = "openid") String openid){
		 return server.searchLottery(openid);
	}
    
    @RequestMapping(value = "/test",method=RequestMethod.GET,produces = "text/json;charset=UTF-8")
    @ResponseBody
    public void testLottery(){
    	for(int i =0 ; i< 100000 ;i ++){
    		Map resout = server.lotteryStart(UUID.randomUUID().toString());
    		if((boolean) resout.get("resout")){
    			System.out.println("第"+i+"次抽中:"+resout.toString());
    		}
    	}
	}
    
}
